import request from '@/utils/request'
import {
  LoginParams,
  UserResponseData,
  CodeResponseData,
  WxResponseData,
  AuthUserResponseData,
  UserAuthInterface,
  DictResponseData,
  AddressResponseData
} from './type'

// 定义请求API
enum API {
  GET_USER_CODE_URL = '/sms/send/',
  USER_LOGIN_URL = '/user/login',
  WX_LOGIN_PARAM_URL = '/user/weixin/getLoginParam',
  // 获取会员信息
  USER_INFO_URL = '/user/auth/getUserInfo',
  // 会员认证
  USER_AUTH_URL = '/user/auth/userAuah',
  // 数据字典获取值
  GET_DICT_VALUE_URL = '/cmn/dict/findByDictCode/',
  // 获取省\区\市\区县
  GET_ADDRESS_URL = '/cmn/dict/findByParentId/'
}

// 获取验证码
export const reqGetCode = (phone: string) =>
  request.get<any, CodeResponseData>(API.GET_USER_CODE_URL + phone)

// 用户登录
export const reqLogin = (data: LoginParams) =>
  request.post<any, UserResponseData>(API.USER_LOGIN_URL, data)

// 获取微信扫码登录生成二维码需要参数接口
export const reqGetWxLoginParam = (wxRedirectUri: string) =>
  request.get<any, WxResponseData>(API.WX_LOGIN_PARAM_URL + `?wxRedirectUri=${wxRedirectUri}`)

// 获取会员信息
export const reqGetUserInfo = () => request.get<any, AuthUserResponseData>(API.USER_INFO_URL)

// 用户认证
export const reqAuth = (data: UserAuthInterface) =>
  request.post<any, AuthUserResponseData>(API.USER_AUTH_URL, { data })

// 通过数据字典获取值
export const reqGetDictByDictCode = (type: string) =>
  request.get<any, DictResponseData>(API.GET_DICT_VALUE_URL + type)

// 通过父级ID获取省\区\市\区县
export const reqGetAddressByParentId = (parentId: number) =>
  request.get<any, AddressResponseData>(API.GET_ADDRESS_URL + parentId)
